﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Golf.WebUI
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        /// <summary>
        /// 计算所有的save值
        /// </summary>
        public void UpdateSave()
        {
            Golf.BLL.Golf_Product bll = new Golf.BLL.Golf_Product();
            DataSet ds = bll.GetAllList();
            DataTable dt = ds.Tables[0];
            int rowsCount = dt.Rows.Count;
            int TureCount = 0;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int n = 0; n < rowsCount; n++)
            {
                int Id = int.Parse(dt.Rows[n]["Id"].ToString());
                Golf.Model.Golf_Product model = bll.GetModel(Id);
                decimal Pro_MarketPrice = decimal.Parse(dt.Rows[n]["Pro_MarketPrice"].ToString());
                decimal Pro_PromotionPrice = decimal.Parse(dt.Rows[n]["Pro_PromotionPrice"].ToString());
                int save = Golf.GetSave._GetSave(Pro_MarketPrice, Pro_PromotionPrice);
                int save1 = (int)model.Pro_Save;
                model.Pro_Save = save;
                try
                {
                    if (bll.Update(model))
                    {
                        TureCount++;
                        sb.Append("[" + Id + "]  --------[" + save1 + "]-------->[" + model.Pro_Save + "]");
                        sb.Append("<br/>");
                    }
                    else
                    {
                        sb.Append("[" + Id + "]" + "---->执行失败");
                        sb.Append("<br/>");
                    }
                }
                catch (Exception)
                {
                }
            }
            Response.Write("商品总数：" + rowsCount + "<br/>执行更改的总数：" + TureCount + "<br/>" + sb.ToString());
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UpdateSave();
        }
    }
}
